<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddColumnNodeTypeInOriginalPlanNodeTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function up()
    {
        $this->table("original_plan_node")
            ->addColumn('step_id', 'biginteger', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '工序ID'])
            ->addColumn('node_type', 'integer', ['limit' => 255, 'null' => false, 'signed' => false, 'default' => 1, 'comment' => '节点类型: 1=交付节点,2=完成节点'])
            ->addColumn('target_step_category_ids', 'string', ['default' => '', 'limit' => 255, 'comment' => '目标环节IDs（下游工序ID对映--的环节）'])
            ->addColumn('stage', 'integer', ['limit' => 255, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '所处阶段 1=T1, 2=非T1'])
            ->addIndex(['project_id', 'node_type', 'delivery_time'], ['type' => 'normal', 'name' => 'node_type_time'])
            ->save();
    }

    public function down()
    {
        $this->table('original_plan_node')
            ->removeColumn('step_id')
            ->removeColumn('node_type')
            ->removeColumn('target_step_category_ids')
            ->removeColumn('stage')
            ->removeIndexByName('node_type_time')
            ->save();
    }
}
